package dao

import (
	"fmt"
	"runtime"
	"shop/config"

	"github.com/go-redis/redis"
)

var redisCli *redis.Client

func InitRedis() {
	redisCli = redis.NewClient(&redis.Options{
		Addr:     config.Conf.RedisAddress,
		Password: config.Conf.RedisPassword,
		DB:       0,
		// 连接池配置
		PoolSize:     runtime.NumCPU() * 5,
		MinIdleConns: 1 + runtime.NumCPU(),
	})
	if err := redisCli.Ping().Err(); err != nil {
		panic(fmt.Sprintf("fail to connect redis, address=%s", config.Conf.RedisAddress))
	}
}

func GetRedisCli() *redis.Client {
	return redisCli
}
